﻿using System.Linq;
using System;
public partial class EditDish : Frame.Pages.BaseInfomationEditBasePage
{
    /// <summary>
    /// 权限编码，需要重新设置
    /// </summary>
    protected override string ActionID
    {
        get { return "0"; }
    }
    protected override bool IsAddCommandColumn
    {
        get
        {
            using (DAL.CMSDALDataContext DContext = new DAL.CMSDALDataContext())
            {
                DAL.BI_SysSettings Setting =
                    DContext.BI_SysSettings.FirstOrDefault(o => o.SettingName == "InterFaceSetting_Dish");
                if (Setting == null)
                {
                    return false;
                }
                return base.IsAddCommandColumn && (Setting.Value == "0");
            }
        }
    }


    protected void gridView_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
        string keyID = e.Values[gridView.KeyFieldName].ToString();
        using (DAL.CMSDALDataContext DContext = new DAL.CMSDALDataContext())
        {
            if (DContext.BLI_ConsumerHisList.Any(o => o.Dish_ID.ToString() == keyID))
            {
                e.Cancel = true;
                throw new Exception("此菜品信息已被使用，不可删除！");
            }
        }
    }
}
